package com.swust.dao;

import com.swust.dao.StudentDao;
import com.swust.po.Student;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import java.util.List;

public class StudentImpl implements StudentDao {
    private SqlSessionFactory sqlSessionFactory;

    public StudentImpl(SqlSessionFactory sqlSessionFactory) {
        this.sqlSessionFactory = sqlSessionFactory;
    }

    @Override
    public Student findBySno(int sno) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        try {
            return sqlSession.selectOne("test.findBySno", sno);
        } finally {
            sqlSession.close();
        }

    }

    @Override
    public List<Student> findbySname(String sname) {
       SqlSession sqlSession=sqlSessionFactory.openSession();
        try {
            return  sqlSession.selectList("test.findBySname",sname);
        } finally {
            sqlSession.close();
        }
    }

    @Override
    public Student insetStudent(Student student) {
        SqlSession sqlSession=sqlSessionFactory.openSession();
        return null;
    }

    @Override
    public Student updateStudent(Student student) {
        return null;
    }

    @Override
    public void deleteStudent(int sno) {

    }
}
